package com.supersit.greensproject.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * Created by Administrator on 2015/11/3.
 */
public class NetWorkInfo {
    /**
     * 判断网络连接情况
     * @param context
     * @return
     */
    public static boolean isNetworkAvailable(Context context){
        ConnectivityManager mgr = (ConnectivityManager)
                context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo[] info = mgr.getAllNetworkInfo();
        if(info != null){
            for(int i=0;i<info.length;i++){
                if(info[i].getState() == NetworkInfo.State.CONNECTED){
                    return true;
                }
            }
        }
        return false;
    }
    /**
     * 打开网络设置界面
     */
    public static void openSetting(Activity activity)
    {
        /**
         Intent intent = new Intent("/");
         ComponentName cm = new ComponentName("com.android.settings",
         "com.android.settings.WirelessSettings");
         intent.setComponent(cm);
         intent.setAction("android.intent.action.VIEW");
         activity.startActivityForResult(intent, 0);
         */
        if(android.os.Build.VERSION.SDK_INT > 10 ){
            activity.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
        }else {
            activity.startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
        }
    }
}
